#include "base.h"
#include "napi/native_api.h"
#include <exception>

#ifndef HAR_METADATA_H
#define HAR_METADATA_H
struct MetadataCallbackData {
    napi_async_work asyncWork;
    napi_deferred deferred;
    napi_ref callback;
    int out_page_num;
};

static void PageSizeExecute(napi_env env, void *data) {
    try {
        MetadataCallbackData *callbackData = reinterpret_cast<MetadataCallbackData *>(data);
        callbackData->out_page_num = ddjvu_document_get_pagenum(document);
    } catch (std::exception &e) {
    }
}

static void PageSizeComplete(napi_env env, napi_status status, void *data) {
    MetadataCallbackData *callbackData = reinterpret_cast<MetadataCallbackData *>(data);
    napi_value result;
    napi_create_int32(env, callbackData->out_page_num, &result);
    napi_resolve_deferred(env, callbackData->deferred, result);
    napi_delete_async_work(env, callbackData->asyncWork);
    delete callbackData;
}
#endif
